<!--
Copyright 2017 Google Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing permissions and limitations under
the License.
-->

<link rel="import" href="../../components/shared-styles/shared-styles.html">
<link rel="import" href="../../modules/file-manager-factory/file-manager-factory.html">
<link rel="import" href="../../modules/template-manager/template-manager.html">
<link rel="import" href="../../modules/utils/utils.html">

<link rel="import" href="../../bower_components/polymer-decorators/polymer-decorators.html">
<link rel="import" href="../../bower_components/paper-spinner/paper-spinner.html">

<dom-module id="table-preview">
  <template>
    <style include="datalab-shared-styles">
      #openInNotebookButton {
        background-color: var(--paper-blue-600);
        color: white;
        width: 150px;
      }
      #openInNotebookButton:hover{
        @apply --shadow-elevation-4dp;
      }
      #container {
        padding: 0px 20px;
        height: 100%;
        overflow-y: auto;
        color: var(--primary-fg-color);
      }
      .description {
        font-style: italic;
        overflow-wrap: break-word;
      }
      table {
        border-spacing: 1px;
        padding: 0 0 4px 0;
        width: 100%;
      }
      td.field {
        padding: 10px;
        background-color: #eee;
      }
      td.value {
        padding: 10px;
        background-color: #fff;
      }
      .separator {
        margin: 20px 0px;
      }
    </style>
    <div id="container" hidden$={{!_table}}>
      <h3>Table Details: <span id="tableId">{{_table.tableReference.tableId}}</span></h3>
      <span class="bold">Project: </span>
      <span id="projectId">{{_table.tableReference.projectId}}</span>
      <br>
      <br>
      <span class="bold">Dataset: </span>
      <span id="datasetId">{{_table.tableReference.datasetId}}</span>
      <br>
      <br>
      <div hidden$={{!_table.description}}>
        <div class="bold">Description</div>
        <br>
        <div class="description">{{_table.description}}</div>
        <br>
      </div>
      <table>
        <tr>
          <td class="bold field">Table Size</td>
          <td id="tableSize" class="value">{{tableSize}}</td>
        </tr>
        <tr>
          <td class="bold field">Long Term Storage Size</td>
          <td id="longTermTableSize" class="value">{{longTermTableSize}}</td>
        </tr>
        <tr>
          <td class="bold field">Number of Rows</td>
          <td id="numRows" class="value">{{numRows}}</td>
        </tr>
        <tr>
          <td class="bold field">Creation Time</td>
          <td id="creationTime" class="value">{{creationTime}}</td>
        </tr>
        <tr>
          <td class="bold field">Last Modified</td>
          <td id="lastModifiedTime" class="value">{{lastModifiedTime}}</td>
        </tr>
        <tr>
          <td class="bold field">Data Location</td>
          <td id="location" class="value">{{_table.location}}</td>
        </tr>
        <!--TODO: Consider showing the table's label somewhere-->
      </table>

      <hr class="separator">

      <div class="bold">Schema</div>
      <br>

      <table id="schema">
        <template is="dom-repeat" items={{schemaFields}} as="field">
          <tr>
            <td class="bold field">{{field.name}}</td>
            <td class="value">{{field.type}}</td>
            <td class="value">{{_formatMode(field.mode)}}</td>
            <!--TODO: Consider showing the field's description somehow-->
          </tr>
        </template>
      </table>

    </div>
  </template>
</dom-module>

<script src="table-preview.js"></script>
